package yesjava;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.Serializable;

/**
 * 演示 单元测试  junit
 */
public class MyTest {
    @Before
    public void before() {
//        System.out.println("运行任何测试方法之前，运行该方法  1  ");
    }

    @After
    public void after() {
//        System.out.println("运行任何测试方法之后，运行该方法  2  ");
    }

    /**
     *
     */
    @Test
    public void test1() {
        // 子类对象指向父类引用
        Person p1 = new Teacher();// 向上转型，客观
        p1.say();
        if (p1 instanceof Student) {
            Student s1 = (Student) p1; // 向下转型，主观
            s1.study();
        } else {
            System.out.println("不是一个学生！");
        }
//        fn(new Person());
        fn((Person) (new Student()));//如果没有多态，这样代码随处可见。
        fn(new Teacher());
    }

    public void fn(Person person) {
        System.out.println("我就是那么无聊");
    }

    @Test
    public void test2() {
        Student p1 = new Student();
       /* Person p2 = new Student();
        Teacher tp2= (Teacher)p2;
        Student sp2= (Student)p2;*/

        Object p3 = new Student();

       /* System.out.println(p1 instanceof Student);
        System.out.println(p1 instanceof Person);
        System.out.println(p1 instanceof Object);*/

        System.out.println("Object  :" + (p3 instanceof Object));
        System.out.println("Student :" + (p3 instanceof Student));
        System.out.println("Teacher :" + (p3 instanceof Teacher));
        System.out.println("String  :" + (p3 instanceof String));
        System.out.println("Integer :" + (p3 instanceof Integer));
        System.out.println("Serializable : " + (p3 instanceof Serializable));

    }

//    接口
    @Test
    public void test3() {
        /*Person person = new Student();
        person.eat();*/
        Live live = new Student();
        live.sleep();
    }




}
